package com.eurobcoin;

import java.util.ArrayList;
import java.util.List;

public class EurobcoinTable {

	public static final int ROWS_PER_PAGE = 10;
	
	private List<Object> rows; //
	
	private int totalElements; //
	
	private int selectedPage; //
	
	private boolean showStartDots = false;
	
	private boolean showEndDots = false;
	
	public EurobcoinTable() {
		this.rows = new ArrayList<Object>();
	}
	
	public void clearRows() {
		this.rows.clear();
	}
	
	public boolean isShowButtonsBar() {
		return this.getLastPage() > 1;
	}

	public void addRow(Object o) {
		this.rows.add(o);
	}
	
	public int getTotalElements() {
		return totalElements;
	}

	public void setTotalElements(int totalElements) {
		this.totalElements = totalElements;
	}

	public int getFirstElement() {
		return ((selectedPage - 1) * ROWS_PER_PAGE) + 1;
	}

	public int getFinalElement() {
		int finalElement = getFirstElement() + ROWS_PER_PAGE - 1;
		
		if(finalElement > totalElements)
			finalElement = totalElements;
		
		return finalElement;
	}

	public int getLastPage() {
		int mod = totalElements % ROWS_PER_PAGE;
		int totalPages = (totalElements - mod) / ROWS_PER_PAGE;
		if(mod != 0)
			totalPages++;
		
		return totalPages;
	}

	public int getSelectedPage() {
		return selectedPage;
	}

	public void setSelectedPage(int selectedPage) {
		this.selectedPage = selectedPage;
	}

	public List<Integer> getPagesArray() {
		List<Integer> pages = new ArrayList<Integer>();
		for(int i = 0; i < this.getLastPage(); i++) {
			pages.add(i + 1);
		}
		
		return pages;
	}

	public boolean isShowStartDots() {
		return showStartDots;
	}

	public void setShowStartDots(boolean showStartDots) {
		this.showStartDots = showStartDots;
	}

	public boolean isShowEndDots() {
		return showEndDots;
	}

	public void setShowEndDots(boolean showEndDots) {
		this.showEndDots = showEndDots;
	}

	public List<Object> getRows() {
		return rows;
	}
	
}
